#!/bin/bash
# Script for sharing internet connection
# Needs: Correctly configured FireHOL, ifconfig and iwconfig, root permissions and well configured DHCP serverOB
# Version: 0.1
# Currently tested on: Debian Sid (2008-04-06)


if [ $UID -ne 0 ];then
	echo "Must be root to do that!"
	exit 1
fi;

echo -n "Setting interface:" $IFACE
ifconfig $IFACE down &> /dev/null || echo "ifconfig failed on putting $IFACE down - sharing FAILED!" && exit 1
iwconfig $IFACE mode ad-hoc essid $ESSID &> /dev/null || echo "iwconfig failed on setting wireless interface $IFACE - sharing FAILED!" && exit 1
ifconfig $IFACE up &>/dev/null || echo "ifconfig failed on putting $IFACE up - sharing FAILED!" && exit 1
ifconfig $IFACE $IP netmask $NETMASK &> /dev/null || echo "ifconfig failed on setting IP on wireless interface - sharing FAILED!" && exit 1
echo ".... Done"

echo -n "Starting FireHOL"
/etc/init.d/firehol start &> /dev/null || echo "FireHOL failed to start - sharing FAILED!" && exit 1
echo ".... Done"

echo -n "Starting DHCP server"
/etc/init.d/dhcp3-server start &> /dev/null || echo "DHCP3-server failed to start - sharing FAILED" && exit 1
echo ".... Done"

echo "All done, sharing ENABLED"

